﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using DirectShowLib;
using xnaVideo;
using Splicer;
using Splicer.Timeline;

using Draw = System.Drawing; /*Required becuase of ambiguity between 
                               Microsoft.Xna.Framework.Rectangle and
                               System.Drawing.Rectangle */

namespace SmlEngine.Media.Video
{
    /// <summary>
    /// A class used for recording a video from a game.
    /// </summary>
    public class VideoRecorder
    {
        private DefaultTimeline line;
        private Group group;
        private Track track;

        private Draw.Image buffer;

        private float fps;

        private Rectangle source;
        private Game owner;

        /// <summary>
        /// Constructs a new VideoRecorder.
        /// </summary>
        /// <param name="fps">The number of frames, per second, to record.</param>
        /// <param name="source">The area of the screen to record.</param>
        /// <param name="owner">The game to record the video from.</param>
        public VideoRecorder(float fps, Rectangle source, Game owner)
        {
            this.fps = fps;
            this.source = source;
            this.owner = owner;

            line = new DefaultTimeline(fps);
            group = (Group)line.AddVideoGroup("SML Recording", (short)fps, 24, source.Width, source.Height);
            track = (Track)group.AddTrack();
        }

        /// <summary>
        /// Updates the VideoRecorder.
        /// </summary>
        /// <param name="gameTime">The GameTime to use in timing operations.</param>
        public void Update(GameTime gameTime)
        {
            track.AddImage(buffer, 0, 1f / fps);
        }

        /// <summary>
        /// Records one frame from the game.
        /// </summary>
        /// <param name="graphicsDevice">The GraphicsDevice to get the data from.</param>
        public void Draw(GraphicsDevice graphicsDevice)
        {
        }
    }
}
